package com.ait.cms.controller;


import com.ait.cms.entity.EduComment;
import com.ait.cms.service.EduCommentService;
import com.ait.commonutils.Msg;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-07-06
 */
@RestController
@RequestMapping("/cms/comment")
public class EduCommentController {

    @Autowired
    private EduCommentService eduCommentService;


    @PostMapping("addComment")
    public Msg addComment(@RequestBody EduComment eduComment){
        boolean save = eduCommentService.save(eduComment);
        if (save){
            return Msg.success();
        }
        return Msg.fail();
    }

    @GetMapping("pageComment")
    public Msg pageComment(Integer currnet,Integer limit,String id){
        Page<EduComment> page = new Page<>(currnet,limit);
        Map<String,Object> map = eduCommentService.getpageComment(page,id);

        return Msg.success().data("comment",map);
    }


    @DeleteMapping("removeComment")
    public Msg removeComment(String id){
        if (eduCommentService.removeById(id)) {
            return Msg.success();
        }

        return Msg.fail();
    }

}

